<?php
require 'Site/Auth.php';

class Account_SigninController extends Zend_Controller_Action {
    public function indexAction() {
        if (Zend_Auth::getInstance()->hasIdentity())
            $this->_redirect('/');
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $_POST = Site_Filter::get($_POST, 'Magicquotes');
            $adapter = new Site_Auth(
                $_POST['username'], $_POST['password']);
            $result = Zend_Auth::getInstance()->authenticate($adapter);
            if ($result->getCode() != Zend_Auth_Result::SUCCESS)
                $this->_redirect('signin/error/invalid');
            $this->_redirect('/');
        }
        $this->view->title = 'Sign In';
    }

    public function errorAction() {
        if (Zend_Auth::getInstance()->hasIdentity())
            $this->_redirect('home');
        $error = end(explode('/', eregi_replace('/ *$', null,
            $this->_request->getRequestUri())));
        if ($error == 'invalid')
            $this->view->error = 'Usuário e/ou senha inválidos.';
        else if ($error == 'restricted')
            $this->view->error = 'Acesso restrito.';
        $this->view->title = 'Sign In';
    }
}
?>
